


import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xim/common/get_style_view.dart';
import 'package:xim/common/style/colors.dart';
import 'package:xim/http/apis/user/user_model.dart';
import 'package:xim/widget/common/state.dart';

class WelcomeLoginStyle extends Style with AppBarMixin {

  final enableFingerprintLogin = true.obs;

  final ModelColor  fingerprintIconsColor = ModelColor(
      darkColor: const Color(0xff46484a),
      lightColor: const Color(0xff46484a)
  );

  /// 提示框背景颜色
  final ModelColor  waringBgColor = ModelColor(
      darkColor: const Color(0xff23272a),
      lightColor: const Color(0xffffffff)
  );


  @override
  Color get appBarBgColor => Colors.transparent;

  @override
  double get elevation => 0;

  /// 标题
  Widget get title => Text(
    "欢迎回来",
    style: TextStyle(
        fontWeight: FontWeight.w500,
        fontSize: 16,
        color: textColor.color
    ),
  );

  /// fingerprint
  Widget fingerprintOption(bool status, ValueChanged<bool?>? onChangeFunc) => Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      Text("使用指纹登录?", style: TextStyle(color: textColor.color),),
      Checkbox(value: status, onChanged: onChangeFunc,)
    ],
  );

  /// password input
  Widget passwordInput(FocusNode focusNode,
      void Function(String? value) iptFinish,
      void Function() fingerprintValid) => TextFormField(
    obscureText: true,
    onSaved: iptFinish,
    style: TextStyle(
      color: textColor.color,
      fontSize: 18
    ),
    focusNode: focusNode,
    decoration: InputDecoration(
        contentPadding: const EdgeInsets.symmetric(horizontal: 12,vertical: 1),
        hintStyle: TextStyle(
          color: weakTextColor.color,
          fontSize: 14
        ),
        hintText: "请输入应用密码",
        border: OutlineInputBorder(
            borderSide:BorderSide(
                color: textColor.color
            ),
            gapPadding: 1
        ),
      enabledBorder: OutlineInputBorder(
          borderSide:BorderSide(
              color: textColor.color
          ),
          gapPadding: 1
      ),
      suffixIcon: GestureDetector(
        onTap: fingerprintValid,
        child: Icon(
          Icons.fingerprint_outlined,
          color: fingerprintIconsColor.color,
          size: 28,
        ),
      )
    ),
  );

  /// reset account
  Widget get hintText => Text("重置账号", style: TextStyle(color: textColor.color));

  /// 登录按键
  Widget get loginBtn => Container(
    width: double.infinity,
    margin: const EdgeInsets.symmetric(horizontal: 24),
    padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
    decoration: BoxDecoration(
        border: Border.all(color: textColor.color),
        borderRadius: const BorderRadius.all(Radius.circular(24))
    ),
    child: Center(
      child: Text(
        "登录",
        style: TextStyle(
          color: textColor.color,
          fontSize: 16
        ),
      ),
    ),
  );

  @override
  List<ModelColor> get modelColors => [
    ...super.modelColors,
    fingerprintIconsColor,
    waringBgColor
  ];


  Widget searchBox(){
    var gap = 12.0;
    var textStyle = TextStyle(fontSize: 14, color: textColor.color);
    return Container(
      height: 38,
      margin: EdgeInsets.symmetric(horizontal: gap),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          border: Border.all(color: Colors.grey.shade500)
      ),
      child: TextField(
        style: textStyle,

        decoration: InputDecoration(
            hintText: "搜索",
            border: InputBorder.none,
            prefixIcon: Icon(Icons.search, color: weakTextColor.color,),
            hintStyle: TextStyle(fontSize: 14, color: weakTextColor.color)
        ),
      ),
    );
  }

  Widget item({double height=42,Widget? leftWidget,Widget? rightWidget, double gap=6.0}){
    return SizedBox(
      height: height,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          if(leftWidget!=null) Row(
            children: [
              SizedBox(width: gap,),
              leftWidget,
            ],
          ),
          if(rightWidget!=null) Row(
            children: [
              rightWidget,
              SizedBox(width: gap,),
            ],
          ),
        ],
      ),
    );
  }


  Widget titleItem({required String title}){
    return item(
        leftWidget: Text(title, style: TextStyle(fontSize: 16, color: textColor.color),),
        height: 32,
        gap: 12
    );
  }

}

class _SessionUser extends UserInfoModel{
  _SessionUser({required UserInfoModel user, this.isSelected=false})
      : super(user.id, user.account, user.avatar, user.publicKey, user.name);
  bool isSelected;
}
